<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>.::IFConnect::.</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="../styles/mainadmin.css" type="text/css" rel="stylesheet" media="all" />
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    </h:head>

    <h:body>

        <div id="cabecalho">
            <a href="principalAdmin.xhtml" alt="Administração" title="Voltar a página principal de administração">
                <img src="../images/topadmin.png" width="700" height="100" alt="Área Administrativa" />
            </a>
            <br />
            <div id="logincontrol">
                <h:panelGrid columns="2">
                    <h:outputText value="Bem-vindo #{usuariologin.usuario.nome} #{usuariologin.usuario.sobrenome}  " />
                    <h:form>
                        <h:commandLink value="Logoff" action="#{usuariologin.logout()}"/>
                    </h:form>
                </h:panelGrid>
            </div>
        </div>

        <div id="estrutura">

            <div id="conteudo">
                <h2>Painel de Administração</h2>
                <h3>Cadastro de Campus</h3>

                <h:form id="cad" enctype="multipart/form-data">
                    <p:growl id="messages" />

                    <p:fieldset legend="Informações Gerais">
                        <h:panelGrid columns="4">

                            <h:outputText value="*Nome: " />
                            <p:inputText label="Nome" required="true" value="#{campusMB.campus.nome}" styleClass="campoTexto" />

                            <h:outputText value="*E-mail: " />
                            <p:inputText label="E-mail" required="true" value="#{campusMB.campus.email}" styleClass="campoTexto" />

                            <h:outputText value="*Site: " />
                            <p:inputText label="Site" required="true" value="#{campusMB.campus.site}" styleClass="campoTexto" />

                            <h:outputText value="*Telefone: " />
                            <p:inputMask label="Telefone" required="true" value="#{campusMB.campus.telefone}" mask="(99)9999-9999" />

                            <h:outputText value="*Descrição: " />
                            <p:inputTextarea label="Descrição" required="true" rows="2" cols="60" value="#{campusMB.campus.descricao}" styleClass="campoTextArea" />

                            <h:outputText value="" />
                            <h:outputText value="" />

                        </h:panelGrid>
                        <p:separator/>
                        <h:panelGrid columns="4">

                            <h:outputText value="*Logradouro:" />
                            <p:inputText label="Logradouro" required="true" value="#{campusMB.campus.logradouro}" styleClass="campoTexto" />
                            <h:outputText value="*N°:" />
                            <p:inputText label="Número" required="true" value="#{campusMB.campus.numero}" size="5" />

                            <h:outputText value="*Complemento:" />
                            <p:inputText label="Complemento" value="#{campusMB.campus.complemento}" styleClass="campoTexto" />
                            <h:outputText value="*Bairro: " />
                            <p:inputText label="Bairro" required="true" value="#{campusMB.campus.bairro}" styleClass="campoTexto" />

                            <h:outputText value="*CEP: " />
                            <p:inputMask label="CEP" required="true" value="#{campusMB.campus.cep}" mask="99.999-999" />
                            <h:outputText value="" />
                            <h:outputText value="" />

                            <h:outputText value="*Cidade: " />
                            <p:inputText label="Cidade" required="true" value="#{campusMB.campus.cidade}" styleClass="campoTexto" />
                            <h:outputText value="*UF: " />
                            <p:selectOneMenu value="#{campusMB.uf}" effect="fade">  
                                <f:selectItem itemLabel="Selecione o estado" noSelectionOption="true" />  
                                <f:selectItems value="#{campusMB.estados}" var="player" itemLabel="#{campusMB.uf}" itemValue="#{campusMB.uf}" />
                            </p:selectOneMenu>

                        </h:panelGrid>

                        <p:separator/>

                        <h:panelGrid columns="4">

                            <h:outputText value="Latitude: " />
                            <p:inputText id="lat" label="Latitude" value="#{campusMB.campus.latitude}" styleClass="campoTexto" readonly="true"/>
                            <h:outputText value="" />
                            <h:outputText value="" />

                            <h:outputText value="Longitude: " />
                            <p:inputText id="lng" label="Longitude" value="#{campusMB.campus.longitude}" styleClass="campoTexto" readonly="true"/>
                            <p:commandButton value="Mapa" onclick="mapaDialog.show()" image="ui-icon-pin-s"/>

                        </h:panelGrid>

                        <p:separator/>

                        <h:panelGrid columns="4">
                            <h:outputText value="Foto:" />                                
                            <p:fileUpload fileUploadListener="#{campusMB.fileUploadAction}" mode="advanced" sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
                        </h:panelGrid>

                        <p:commandButton value="Salvar" update=":form, :cad" action="#{campusMB.addCampus}" image="ui-icon ui-icon-disk"/>

                    </p:fieldset>

                    <p:dialog header="Geolocalização do Campus" widgetVar="mapaDialog" resizable="false" width="625" height="400" 
                              showEffect="fade" hideEffect="explode" modal="true">

                        <p:gmap center="-7.04221077502565,-37.21315337353519" zoom="7" type="HYBRID" style="width:600px;height:400px" onPointClick="mapaDialog.hide()">
                            <p:ajax event="pointSelect" listener="#{campusMB.onPointSelect}" update=":cad:lat, :cad:lng" />
                        </p:gmap> 

                    </p:dialog>

                </h:form>



                <h3>Campi cadastrados</h3>

                <h:form id="form">


                    <p:dataTable id="table-campus" value="#{campusMB.listaCampus}" var="campus" tableStyle="width:100%" paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15">

                        <p:column headerText="ID" sortBy="#{campus.id}" >  
                            <h:outputText value="#{campus.id}" />  
                        </p:column>

                        <p:column headerText="NOME" sortBy="#{campus.nome}" >  
                            <h:outputText value="#{campus.nome}" />  
                        </p:column>

                        <p:column headerText="CIDADE" sortBy="#{campus.cidade}" >  
                            <h:outputText value="#{campus.cidade}" />  
                        </p:column>

                        <p:column headerText="UF" sortBy="#{campus.uf}" >  
                            <h:outputText value="#{campus.uf}" />  
                        </p:column>

                        <p:column style="width:40px">  
                            <p:commandButton id="selectButton" update=":form:display" oncomplete="campusDialog.show()" icon="ui-icon-search" title="Ver">  
                                <f:setPropertyActionListener value="#{campus}" target="#{campusMB.campusSelecionado}" />
                            </p:commandButton>  
                        </p:column>

                    </p:dataTable>

                    <p:dialog header="Detalhes do Campus" widgetVar="campusDialog" resizable="false" id="campusDlg" dynamic="true" 
                              showEffect="fade" hideEffect="explode" modal="true">  

                        <h:panelGrid id="display" columns="1" cellpadding="4" style="margin:0 auto;">

                            <f:facet name="header">
                                <h:graphicImage alt="campus" height="100" library="campus" name="#{campusMB.campusSelecionado.foto}"/>
                            </f:facet>

                            <h:panelGrid columns="4" cellpadding="4">

                                <h:outputText value="NOME: " />
                                <h:outputText value="#{campusMB.campusSelecionado.nome}" style="font-weight:bold"/>
                                <h:outputText value="E-MAIL: " />
                                <h:outputText value="#{campusMB.campusSelecionado.email}" style="font-weight:bold"/>

                                <h:outputText value="SITE: " />
                                <h:outputText value="#{campusMB.campusSelecionado.site}" style="font-weight:bold"/>
                                <h:outputText value="TELEFONE: " />
                                <h:outputText value="#{campusMB.campusSelecionado.telefone}" style="font-weight:bold"/>

                                <h:outputText value="DESCRIÇÃO: " />
                                <h:outputText value="#{campusMB.campusSelecionado.descricao}" style="font-weight:bold"/>
                                <h:outputText value="" />
                                <h:outputText value="" />

                            </h:panelGrid>


                            <h:panelGrid columns="4" cellpadding="4" >

                                <h:outputText value="LOGRADOURO:" />
                                <h:outputText value="#{campusMB.campusSelecionado.logradouro}" style="font-weight:bold"/>
                                <h:outputText value="N°:" />
                                <h:outputText value="#{campusMB.campusSelecionado.numero}" style="font-weight:bold"/>

                                <h:outputText value="COMPLEMENTO:" />
                                <h:outputText value="#{campusMB.campusSelecionado.complemento}" style="font-weight:bold"/>
                                <h:outputText value="BAIRRO: " />
                                <h:outputText value="#{campusMB.campusSelecionado.bairro}" style="font-weight:bold"/>

                                <h:outputText value="CEP: " />
                                <h:outputText value="#{campusMB.campusSelecionado.cep}" style="font-weight:bold"/>
                                <h:outputText value="" />
                                <h:outputText value="" />

                                <h:outputText value="CIDADE: " />
                                <h:outputText value="#{campusMB.campusSelecionado.cidade}" style="font-weight:bold"/>
                                <h:outputText value="UF: " />
                                <h:outputText value="#{campusMB.campusSelecionado.uf}" style="font-weight:bold"/>

                            </h:panelGrid>


                            <h:panelGrid columns="1">

                                <h:outputText value="GEOLOCALIZAÇÃO" style="font-weight:bold"/>
                                <p:gmap center="#{campusMB.campusSelecionado.latitude},#{campusMB.campusSelecionado.longitude}" zoom="17" type="HYBRID" style="width:200px;height:150px" disableDefaultUI="true" disableDoubleClickZoom="true"/>

                            </h:panelGrid>

                            <h:panelGrid columns="2">
                                <p:commandButton value="Excluir" onclick="confirmation.show()" icon="ui-icon-trash" type="button" />
                                <p:commandButton value="Atualizar" update=":cad" action="#{campusMB.atualizaCampus()}" icon="ui-icon-refresh" oncomplete="campusDialog.hide();" />
                            </h:panelGrid>


                        </h:panelGrid>

                    </p:dialog>  

                    <p:confirmDialog id="confirmDialog" message="Tem certeza que deseja excluir o campus?" header="Excluir Campus" severity="alert" widgetVar="confirmation">  
                        <p:commandButton id="confirm" value="Confirmar" update=":form, :cad" oncomplete="confirmation.hide()" action="#{campusMB.excluirCampus()}" />  
                        <p:commandButton id="decline" value="Cancelar" onclick="confirmation.hide()" type="button" />   
                    </p:confirmDialog>

                </h:form>
            </div>

        </div>

    </h:body>
</html>
